package rmmk.datasources.parsing;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;

/**
 * Klasa wczytuje labelki dla kategorii z plików z labelkami kategorii :)
 * @author marcin
 *
 */
public class LabelSets {
	Vector<String> TOPICS, PLACES, PEOPLE;// , ORGS, EXCHANGES;

	public LabelSets() {
		this.TOPICS = new Vector<String>();
		this.PLACES = new Vector<String>();
		this.PEOPLE = new Vector<String>();
	}

	public void readDefault() {
		HashMap<ClassTypes, String> readThose = new HashMap<ClassTypes, String>();

		readThose.put(ClassTypes.PEOPLE, "/all-people-strings.lc.txt");
		readThose.put(ClassTypes.TOPICS, "/all-topics-strings.lc.txt");
		readThose.put(ClassTypes.PLACES, "/all-places-strings.lc.txt");

		readFromMap(readThose);
	}

	private void readFromMap(Map<ClassTypes, String> files) {
		BufferedReader br = null;

		for (Entry<ClassTypes, String> entry : files.entrySet()) {
			Vector<String> tmp = this.getLabelsFor(entry.getKey());

			try {
				String sCurrentLine;
				URI path = this.getClass().getResource(entry.getValue())
						.toURI();
				br = new BufferedReader(new FileReader(path.getPath()));

				while ((sCurrentLine = br.readLine()) != null) {
					tmp.add(sCurrentLine);
				}
			} catch (FileNotFoundException ex) {
				ex.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (URISyntaxException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public Vector<String> getLabelsFor(ClassTypes type) {
		switch (type) {
		case PEOPLE:
			return this.PEOPLE;
		case PLACES:
			return this.PLACES;
		case TOPICS:
			return this.TOPICS;
		}
		return null;
	}

}
